import java.util.Scanner;

/**
 * 整数与IP地址间的转换
 * 原理：ip地址的每段可以看成是一个0-255的整数，把每段拆分成一个二进制形式组合起来，然后把这个二进制数转变成
 * 一个长整数
 */
public class HJ33 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String ip = scanner.nextLine();
            String num = scanner.nextLine();

            System.out.println(ipToNum(ip));
            System.out.println(numToIp(num));
        }
    }

    private static String numToIp(String num) {
        String s = Long.toBinaryString(Long.parseLong(num));
        while (s.length() < 32){
            s = '0'+s;
        }
        String[] strings = new String[4];

        for (int i = 0; i < 4; i++) {
            String substring = s.substring(8 * i, 8 + 8 * i);
            int n = Integer.parseInt(substring, 2);
            strings[i] = String.valueOf(n);
        }

        return String.join(".",strings);
    }

    private static long ipToNum(String ip) {
        String[] strings = ip.split("\\.");
        StringBuffer sb = new StringBuffer();
        for (String s : strings) {
            String s1 = Integer.toBinaryString(Integer.parseInt(s));
            while (s1.length()<8){
                s1 = '0'+s1;
            }
            sb.append(s1);
        }

        return Long.parseLong(sb.toString(),2);
    }
}
